import numpy as np
import pandas as pd
import scipy.interpolate as spi
from matplotlib import pyplot as plt

df1 = pd.read_excel("NACA 2414/Re=60400/UIUC_Re60400.xlsx", engine='openpyxl')
df2 = pd.read_excel("NACA 2414/Re=100800/UIUC_Re100800.xlsx", engine='openpyxl')
df3 = pd.read_excel('NACA 2414/Re=201600/UIUC_Re201600.xlsx', engine='openpyxl')
df4 = pd.read_excel("NACA 2414/Re=302700/UIUC_Re302700.xlsx", engine='openpyxl')

x = np.array(df1.iloc[:, 0])
y = np.array(df1.iloc[:, 4])

# 中间点差值==========================================

# new_x = np.empty(0, int)
# new_x = []
#
# i = 0
# while i < 10:
#     # new_x = np.append(new_x, (x[i] + x[i + 1]) / 2)
#     new_x.append((x[i] + x[i + 1]) / 2)
#     i += 1

# 范围密集差值点==========================================
new_x = np.arange(x[0], x[10], 0.1)

np.array(new_x)

# 三次样条拟合

ipo3 = spi.splrep(x, y, k=3)  # 样本点导入，生成参数
iy3 = spi.splev(new_x, ipo3)  # 根据观测点和样条参数，生成插值

# 作图
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

plt.xlabel('α')
plt.ylabel('Cl')
plt.scatter(x, y, c="black", s=10, label='样本点')
plt.plot(new_x, iy3, c="red", label='插值点')
plt.title('三次样条插值')
plt.legend(loc=0)  # 图例位置自
plt.show()

# 数据
print(new_x)
print(iy3)
